﻿using System.Collections.Generic;
using Windows.ApplicationModel.Resources.Core;

namespace com.IronOne.BoardPACWinApp.Helpers
{
    public static class ResourceHandler
    {
        private static readonly ResourceMap ResourceStringMap;
        private static readonly ResourceContext Context;
        //Create folder with preferred language code (Ex: en, es, fr)
        //Create a resource file named as Resources.resw
        //Change the selectedLanguage variable with preferred language code
        static ResourceHandler()
        {
            const string selectedLanguage = "en";
            Context = ResourceContext.GetForCurrentView();

            var lang = new List<string> {selectedLanguage};
            Context.Languages = lang;
            ResourceStringMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
        }

        /// <summary>
        ///     Error codes: (Based on Service layer's folder structure)
        ///     Auth: 100-199
        ///     Init: 200-299
        ///     Xml : 300-399
        /// </summary>
        /// <param name="key">String name of the resource</param>
        /// <returns>Resource </returns>
        public static string Get(string key)
        {
            return ResourceStringMap.GetValue(key, Context).ValueAsString;
        }
    }
}